from typing import Self
from node_class import Node
import pygame
from pygame_single import Pygame_Single
__NODE_EFFECTOR_DICT:dict#[int,NodeEffector]
LINES_RECT:dict[str,pygame.Rect]
def Draw_Line(list,screen:pygame.Surface):
    #pygame.draw.line(screen, (0, 0, 0), (x1, y1), (x2, y2), 5)
    pass
class NodeEffector:
    node_data:Node
    rect:pygame.Rect
    screen_coord_x:int
    screen_coord_y:int
    Static_Dict={}
    Static_Lines_Dict:dict[tuple[int,int],pygame.Rect]={}#[(id_max,id_min),rect]
    @property
    def id(self)->int:
        return self.node_data.id
    

    def __init__(self, node:Node):
        self.node_data = node
        self.__TransformScreenCoord()
        # if(self.Static_Dict is None):
        #     self.Static_Dict={}
        self.Static_Dict[node.id]=self
    def __TransformScreenCoord(self):
        '''
        将坐标转换为屏幕坐标
        '''
        self.screen_coord_x=int(self.node_data.x*40)+20
        self.screen_coord_y=int(self.node_data.y*40)+100

    def DrawCircles(self,screen:pygame.Surface):
        self.rect=pygame.draw.circle(screen, (255,0,0), (self.screen_coord_x, self.screen_coord_y), 10)
    def DrawTexts(self,screen:pygame.Surface,font:pygame.font.Font):
        text = font.render(f'{self.id}', True, (0, 255, 0))
        screen.blit(text, (self.screen_coord_x-10, self.screen_coord_y-10))
    def DrawLines(self,screen:pygame.Surface):
        for neighbor in self.node_data.neighbors.keys():
            key=tuple(sorted((self.id,neighbor)))
            if(key in self.Static_Lines_Dict.keys()):
                continue
            self.Static_Lines_Dict[key]=pygame.draw.line(screen, (0, 0, 0), (self.screen_coord_x, self.screen_coord_y), (self.Static_Dict[neighbor].screen_coord_x, self.Static_Dict[neighbor].screen_coord_y), 5)
    def Draw(self):
        self.DrawLines(Pygame_Single.instance.screen)
        self.DrawCircles(Pygame_Single.instance.screen)
        self.DrawTexts(Pygame_Single.instance.screen,Pygame_Single.instance.font)
    @staticmethod
    def Static_DrawOneLine(id_1:int,id_2:int):
        node1:NodeEffector=NodeEffector.Static_Dict[id_1]
        node2:NodeEffector=NodeEffector.Static_Dict[id_2]
        pygame.draw.line(Pygame_Single.instance.screen, (0, 255, 0), (node1.screen_coord_x, node1.screen_coord_y), (node2.screen_coord_x, node2.screen_coord_y), 5)
    @staticmethod
    def Static_DrawMap():
        for node_effector in NodeEffector.Static_Dict.values():
            node_effector:NodeEffector
            node_effector.DrawLines(Pygame_Single.instance.screen)
        for node_effector in NodeEffector.Static_Dict.values():
            node_effector:NodeEffector
            node_effector.DrawCircles(Pygame_Single.instance.screen)
        for node_effector in NodeEffector.Static_Dict.values():
            node_effector:NodeEffector
            node_effector.DrawTexts(Pygame_Single.instance.screen,Pygame_Single.instance.font)
       
    
    #@staticmethod
    